<?php 
    include("header.php");
    setTabIndex(1);
    createPage("Liga - Poll");
?>

<head>
    <title>Liga - Poll</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="assets/css/default.css" rel="stylesheet" type="text/css">

    <style type="text/css">
        @import "/assets/js/dojo-release-1.1.0/dijit/themes/tundra/tundra.css";
        @import "/assets/js/dojo-release-1.1.0/dojo/resources/dojo.css"
    </style>
    
    <script type="text/javascript" src="/assets/js/dojo-release-1.1.0/dojo/dojo.js"
      djConfig="parseOnLoad: true"></script>
    
    <script type="text/javascript">
        dojo.require("dijit.Dialog");
        dojo.require("dijit.form.TextBox");
        dojo.require("dijit.form.Button");
        dojo.require("dijit.Editor");
        dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
        dojo.require("dijit._editor.plugins.EnterKeyHandling");
        dojo.require("dijit._editor.plugins.TextColor");
        dojo.require("dijit._editor.plugins.LinkDialog");
        dojo.require("dijit._editor.plugins.EditorImageDialog");
        dojo.require("dojo.parser");  
    </script>
    
    <script>
       function successCommand(data,ioArgs) {
           if (data != '') {
               dojo.byId('pollAlert').className='error';
               dojo.byId('pollAlert').innerHTML=data;
           } else {
               window.location = "/poll/poll.php?id=" + dojo.byId('id').value;
           }
       }       
       
       function errorCommand(data, ioArgs) {
           dojo.byId('pollAlert').className='error';
           dojo.byId('pollAlert').innerHTML='Uw keuze is niet verwerkt. Gelieve contact op te nemen met de webmaster.';
       }
    </script>

</head>

<?php
    $user = $_SESSION['user'];
    
    mysql_connect(DB_SERVER, DB_USER, DB_PWD);
    mysql_select_db(DB_CATALOG);
    
    $result = mysql_query("select p.* from poll p where p.isActive = 1");
    
    $polls = array();
    while ($row = mysql_fetch_assoc($result)) {
        $poll = new Poll;
        $poll->poll_id = $row['poll_id'];
        $poll->title = $row['title'];
        $poll->size = $row['size'];
        $poll->desc = $row['descr'];
        $poll->start = $row['start'];
        $poll->end = $row['end'];
        $poll->active = $row['active'];
        array_push($polls, $poll);
    }
    
    $activePoll = $polls[0];
    
    $result = mysql_query("select po.* from poll_option po where po.poll_id = ".$activePoll->poll_id);
    $pollOptions = array();
    $a = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $a++;
        $option = new PollOption;
        $option->option_id = $row['poll_option_id'];
        $option->poll_id = $row['poll_id'];
        $option->label = $row['label'];
        $option->desc = $row['descr'];
        $option->color = $row['color'];
        $option->count = $row['count'];
        array_push($pollOptions, $option);
    }

    $title = $activePoll->title;
    $enc_title = urlencode($activePoll->title);
    $chs = $activePoll->size;
    
    $b = 0;
    $chd = "t:";
    foreach ($pollOptions as $option) {
        $chd = $chd.$option->count;
        $chdl = $chdl.$option->label;
        $chco = $chco.$option->color;
        $chm= $chm."N*f0*,000000,".$b.",-1,11";
        if (++$b < $a) {
            $chd = $chd."|";
            $chdl = $chdl."|";
            $chm = $chm."|";
            $chco = $chco.",";
        }
        
    }

?> 

<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">

    <tr>
        <td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">
                <tr><td>&nbsp;</td></tr>
            </table>
        </td>
        <td id="header" valign="top" width="100%">
            <table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
                <tr>
                    <td bgcolor="#666666" width="70%">
                        <?php include("inc_title.html"); ?>
                    </td>
                    <td bgcolor="#666666" align="right" valign="top">&nbsp;

                    </td>
                </tr>
            </table>
            <table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
                <tr>
                    <td>&nbsp;</td>
                    <?php include("inc_sublinks.html"); ?>   
                </tr>
                <tr><td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="/assets/images/spacer.gif" alt="" height="1" width="1"></td></tr>
                <tr>
                    <td>&nbsp;</td>
                    <td valign="top">
                        <table align="left" cellspacing="10" width="100%">
                            <tr>
                                <td colspan="4">
                                    <span class="blackHeaderLarge">Huidige poll</span> (<a href="/poll/poll.php?id=<?=$activePoll->poll_id?>">resultaten</a>)
                                    <br>&nbsp;<br>
                                    <strong><?=$title?></strong>
                                    &nbsp;&nbsp;
                                    <span class="hidden" id="pollAlert"></span>
                                    <p/>
                                    <form id="pollForm" method="post">
                                    <?
                                    foreach ($pollOptions as $option) {
                                    ?>
                                    
                                          <input type="radio" name="option" id="<?=$option->option_id?>" value="<?=$option->option_id?>">
                                          <label for="<?=$option->option_id?>"><?=$option->desc?></label>
                                          <br><br>
                                    
                                    <?
                                    }
                                    ?>
                                    <div style="border: 1px solid #ccc" class="tundra">
                                    <strong>Uw feedback</strong>
                                    <textarea id="commentEditor" dojoType="dijit.Editor" height="100"
                                        plugins="['undo', 'redo', 'cut', 'copy', 'paste',
                                        '|', 'bold','italic','underline',
                                        '|','createLink','foreColor','hiliteColor']"
                                        styleSheets="/assets/js/dojo-release-1.1.0/dojo/resources/dojo.css"></textarea>
                                    <input type="hidden" id="id" name="id" value="<?=$activePoll->poll_id?>" />
                                    <input type="hidden" id="comment" name="comment" />
                                    </form>
                                    <button dojoType="dijit.form.Button" id="submitButton" class="tundra">
                                    Doorsturen
                                    <script type="dojo/method" event="onClick">
                                        dojo.byId('comment').value = dijit.byId('commentEditor').getValue();
                                        dojo.xhrPost({
                                            url: '/poll/submit_poll.php',
                                            load: successCommand,
                                            error: errorCommand,
                                            form: 'pollForm'
                                        });
                                    </script>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
                              
<?php include("footer.php") ?>